home *** CD-ROM | disk | FTP | other *** search
- /*
- * http_auth: authentication
- *
- * Rob McCool
- *
- */
-
-
- #include "httpd.h"
-
- char user[MAX_STRING_LEN];
-
-
- void auth_bong(char *s) {
- char errstr[MAX_STRING_LEN];
-
- /* debugging */
- if(s) {
- sprintf(errstr,"%s authorization: %s",remote_name,s);
- log_error(errstr);
- }
- if(!strcmp(auth_type,"Basic")) {
- sprintf(errstr,"Basic realm=\"%s\"",auth_name);
- die(AUTH_REQUIRED,errstr,stdout); /* AAAAAAGH stdout */
- }
- else {
- sprintf(errstr,"Unknown authorization method %s",auth_type);
- die(SERVER_ERROR,errstr,stdout); /* AAAAAAAAGH stdout */
- }
- }
-
- void check_auth(security_data *sec, int m) {
- #ifndef NO_SECURITY
- char at[MAX_STRING_LEN];
- char ad[MAX_STRING_LEN];
- char sent_pw[MAX_STRING_LEN];
- char real_pw[MAX_STRING_LEN];
- char t[MAX_STRING_LEN];
- char w[MAX_STRING_LEN];
- register int x;
- int grpstatus;
-
- if((!auth_name) || (!auth_type) || (!auth_pwfile)) {
- char errstr[MAX_STRING_LEN];
-
- sprintf(errstr,
- "httpd: authorization required for %s but not configured",sec->d);
- die(SERVER_ERROR,errstr,stdout); /* AAAAAGH stdout */
- }
-
- if(!auth_line[0])
- auth_bong(NULL);
-
- sscanf(auth_line,"%s %s",at,t);
- if(strcmp(at,auth_type))
- auth_bong("type mismatch");
- uudecode(t,(unsigned char *)ad,MAX_STRING_LEN);
- getword(user,ad,':');
- strcpy(sent_pw,ad);
- if(!get_pw(user,real_pw))
- auth_bong("user not found");
- /* anyone know where the prototype for crypt is? */
- if(strcmp(real_pw,(char *)crypt(sent_pw,real_pw)))
- auth_bong("password mismatch");
- if(auth_grpfile)
- grpstatus = init_group(auth_grpfile);
- else
- grpstatus = 0;
-
- for(x=0;x<sec->num_auth[m];x++) {
- strcpy(t,sec->auth[m][x]);
- getword(w,t,' ');
- if(!strcmp(w,"valid-user"))
- goto found;
- if(!strcmp(w,"user")) {
- while(t[0]) {
- getword(w,t,' ');
- if(!strcmp(user,w))
- goto found;
- }
- }
- else if(!strcmp(w,"group")) {
- if(!grpstatus)
- auth_bong("group required and grpfile unreadable");
- while(t[0]) {
- getword(w,t,' ');
- if(in_group(user,w)) {
- log_error("allowing group");
- goto found;
- }
- }
- }
- else
- auth_bong("require not followed by user or group");
- }
- if(grpstatus) kill_group();
- auth_bong("user denied");
-
- found:
- if(grpstatus)
- kill_group();
- #endif
- }
-